home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / SRCLIMIT.CPP < prev    next >
C/C++ Source or Header  |  1994-07-31  |  6KB  |  208 lines

  1. // Copyright 1994 by Jon Dart.  All Rights Reserved.
  2.  
  3. #include "srclimit.h"
  4. #include "srclimt2.h"
  5. #include "constant.h"
  6. #include <wpglob.h>
  7.  
  8. #define IDP_SEARCHTYPE 101
  9. #define IDP_FIXEDPLY 102
  10. #define IDP_TIMELIMIT 103
  11. #define IDP_GAME_LIMIT 104
  12. #define IDP_TOURNAMENT 105
  13. #define IDP_MOVES_OR_PLY 108
  14. #define IDP_MINUTES 109
  15. #define IDP_PLY_TEXT 110
  16. #define IDP_MINUTES_TEXT 111
  17. #define IDP_SECONDARY 112
  18.  
  19. WPControlMap SearchLimitDialog::ControlMap[] = 
  20. {
  21.    cmRBgp( IDP_SEARCHTYPE, Search_Limit_Options, search_type, 4 )
  22.    cmEdit( IDP_MOVES_OR_PLY, Search_Limit_Options, move_or_ply )
  23.    cmEdit( IDP_MINUTES, Search_Limit_Options, time_limit )
  24.    cmEnd( IDP_SEARCHTYPE )
  25. };
  26.  
  27. Search_Limit_Options::Search_Limit_Options()
  28. {
  29. }
  30.  
  31. Search_Limit_Options::Search_Limit_Options( const Time_Control &tc,
  32.   const Control c )
  33. {
  34.     const Search_Limit limit = tc.get_search_limit();
  35.     switch (tc.get_search_type())
  36.     {
  37.         case Fixed_Ply:
  38.        search_type = 0;
  39.          wsprintf(move_or_ply,"%d",
  40.          limit.max_ply);
  41.        time_limit[0] = '\0';
  42.        break;
  43.         case Time_Limit:
  44.        search_type = (c == First) ? 1 : 0;
  45.          wsprintf(move_or_ply,"%ld",
  46.           limit.seconds);
  47.        time_limit[0] = '\0';
  48.            break;
  49.         case Game:
  50.        search_type = (c == First) ? 2 : 1;
  51.          wsprintf(move_or_ply,"%d",
  52.           limit.limit.minutes);
  53.        time_limit[0] = '\0';
  54.            break;
  55.     case Tournament:
  56.        search_type = (c == First) ? 3 : 2;
  57.          wsprintf(move_or_ply,"%d",
  58.           limit.limit.moves);
  59.          wsprintf(time_limit,"%d",
  60.           limit.limit.minutes);
  61.        break;
  62.        case None:
  63.            search_type = (c == First) ? 4 : 0;
  64.            *time_limit = *move_or_ply = '\0';
  65.        break;
  66.     }
  67. }
  68.  
  69. Boolean Search_Limit_Options::parse(Time_Control &tc, const Control c)
  70. {
  71.      int minutes, moves;
  72.      char msg[100];
  73.      Search_Limit limit;
  74.      int index = search_type;
  75.      if (c == Second)
  76.      {
  77.          // The secondary search dialog has buttons that don't correspond
  78.      // in order to the enum Search_Type.  So compensate for that here:
  79.      static int indexes[] = { 4, 2, 3, 0, 0 };
  80.      index = indexes[search_type];
  81. #ifdef RANGE_CHECK
  82.      assert(index != 0);
  83. #endif
  84.      }
  85.      switch (index)
  86.      {
  87.         case 0: /* Fixed_Ply */
  88.            limit.max_ply = atoi(move_or_ply);
  89.        if (limit.max_ply <= 0) limit.max_ply = 2;
  90.        if (limit.max_ply > Constants::MaxPly) 
  91.           limit.max_ply = Constants::MaxPly;
  92.        break;
  93.        case 1: /* Time_Limit */
  94.            {
  95.        unsigned long seconds = atol(move_or_ply);
  96.            limit.seconds = seconds;
  97.        break;
  98.            }
  99.        case 2: /* Game */
  100.            {
  101.        int minutes = atoi(move_or_ply);
  102.            limit.limit.minutes = minutes;
  103.        break;
  104.            }
  105.        case 3: /* Tournament */
  106.        moves = atoi(move_or_ply);
  107.        minutes = atoi(time_limit);
  108.        if (moves && minutes)
  109.        {
  110.           limit.limit.moves = moves;
  111.           limit.limit.minutes = minutes;
  112.       }
  113.       break;
  114.      }
  115.      tc.set_search_type((Search_Type)index);
  116.      tc.set_search_limit(limit);
  117.      return True;
  118. }
  119.  
  120. SearchLimitDialog::SearchLimitDialog(WPWin *pwin, 
  121.   Search_Limit_Options *primary_options,
  122.   Search_Limit_Options *secndry_options)
  123. : initial_search_type(primary_options->search_type),
  124.   WPDialogModal("SEARCHLIMITS", pwin, ControlMap, primary_options)
  125. {
  126.    secondary_options = secndry_options;
  127.    createWin();         
  128. }
  129.  
  130. void SearchLimitDialog::initDlg()
  131. {
  132. // Note: the Windows++ getControl function appears not to return valid
  133. // data, at least when called from here, so we limit ourselves to direct
  134. // Windows calls
  135.    const HWND hDlg = getHwnd();
  136.    hPly_text = GetDlgItem(hDlg,IDP_PLY_TEXT);
  137.    hMinutes_field = GetDlgItem(hDlg,IDP_MINUTES);
  138.    hMinutes_text = GetDlgItem(hDlg,IDP_MINUTES_TEXT);
  139.    hSecondary = GetDlgItem(hDlg,IDP_SECONDARY);
  140.    new_type(initial_search_type);
  141. }
  142.  
  143. void SearchLimitDialog::new_type(int srctype)
  144. {
  145.    assert(srctype < 4);
  146.    switch (srctype)
  147.    {
  148.      case 0:
  149.        ShowWindow(hMinutes_field,SW_HIDE);
  150.        ShowWindow(hMinutes_text,SW_HIDE);
  151.        EnableWindow(hMinutes_text,FALSE);
  152.        SetWindowText(hPly_text,"Ply:");
  153.        EnableWindow(hSecondary,FALSE);
  154.        break;
  155.     case 1:
  156.        ShowWindow(hMinutes_field,SW_HIDE);
  157.        ShowWindow(hMinutes_text,SW_HIDE);
  158.        EnableWindow(hMinutes_text,FALSE);
  159.        SetWindowText(hPly_text,"Seconds/Move:");
  160.        EnableWindow(hSecondary,FALSE);
  161.        break;
  162.     case 2:
  163.        ShowWindow(hMinutes_field,SW_HIDE);
  164.        ShowWindow(hMinutes_text,SW_HIDE);
  165.        EnableWindow(hMinutes_text,FALSE);
  166.        SetWindowText(hPly_text,"Minutes/Game");
  167.        EnableWindow(hSecondary,FALSE);
  168.        break;
  169.     case 3:
  170.        ShowWindow(hMinutes_field,SW_SHOWNORMAL);
  171.        ShowWindow(hMinutes_text,SW_SHOWNORMAL);
  172.        EnableWindow(hMinutes_text,TRUE);
  173.        // show the label "Moves:" instead of "Ply:"
  174.        SetWindowText(hPly_text,"Moves:");
  175.        EnableWindow(hSecondary,TRUE);
  176.        break;
  177.     }
  178. }
  179.  
  180. BOOL SearchLimitDialog::command(int id, WORD msg)
  181. {
  182.    switch (id) 
  183.    {
  184.    case IDP_FIXEDPLY:
  185.      new_type(0);
  186.      break;
  187.    case IDP_TIMELIMIT:
  188.      new_type(1); 
  189.      break;
  190.    case IDP_GAME_LIMIT:
  191.      new_type(2);
  192.      break;
  193.    case IDP_TOURNAMENT:
  194.      new_type(3);
  195.      break;
  196.    case IDP_SECONDARY:
  197.    {
  198.      SecondaryLimitDialog *aDlg = new SecondaryLimitDialog(this,
  199.         secondary_options);
  200.      delete aDlg;
  201.      break;
  202.    }
  203.    default:
  204.      break;
  205.    }
  206.    return WPDialogModal::command(id, msg); 
  207. }
  208.